<?php

namespace App\Traits\Relation\Inspection;

use App\Models\Inspection\Node;
use App\Models\Project;
use App\Models\Inspection\Circle;

/**
 * 定义线路模型关系
 *
 * Trait LineRelation
 * @package App\Traits\Relation\Inspection
 * Date: 22/04/2018
 * @author George
 */
trait LineRelation
{
    /**
     * 获取节点的圈信息
     *
     * Date: 22/04/2018
     * @author George
     * @return mixed
     */
    public function circles()
    {
        return $this->hasMany(Circle::class, 'line_id', 'id');
    }

    /**
     * 获取当前线路所属项目信息
     *
     * Date: 22/04/2018
     * @author George
     * @return mixed
     */
    public function project()
    {
        return $this->belongsTo(Project::class, 'project_id', 'id');
    }

	/**
	 * 获取线路的所有点
	 *
	 * Date: 06/05/2018
	 * @author George
	 * @return mixed
	 */
	public function nodes()
	{
		return $this->belongsToMany(Node::class, 'circle_node_pivot', 'line_id', 'node_id', 'id', 'id');
    }
}
